package com.hsogoo.avatar.controller.service;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.hsogoo.avatar.annotations.AvatarInvoke;
import com.hsogoo.avatar.api.UserService;
import com.hsogoo.avatar.exceptions.AvatarException;

/**
 * Created by za-huangsaigang on 2018/10/17.
 */
@Service
public class ConsumeUserService {

    @AvatarInvoke(registry = "localhost:2181",group = "avatar", version = "1.0.0", limit = 10)
    private UserService userService;

//    @Cacheable(value = "sayHello" , key = "#name", unless="#result == null")
    public String sayHello(String name){
        System.out.println("ConsumerUserService.sayHello..." + name);
        String result = null ;
        try{
            result = userService.sayHello(name);
        }catch (AvatarException e){
            System.out.println("AvatarException occur ..."+  e.getMessage());
            return e.getMessage();
        }
        return result;
    }

}
